#include <maya/MIOStream.h>
#include <maya/MSimple.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MPointArray.h>

DeclareSimpleCommand( mkSumCrvs, PLUGIN_COMPANY, "4.5");


MStatus mkSumCrvs::doIt( const MArgList& ) {

	cout<<"Freaking Curves Man!"<<endl;

	MFnNurbsCurve curveFn;
	MStatus stat; 

	float uu;
	float vv;
	float xx;
	float yy;
	float zz;
	float x;
	float y;
	float z;

	for (int u=0; u<100; u+=2) {

		MPointArray editPoints;

		for (int v=0; v<100; v+=2) {

			uu = 0.03*u;
			vv = 0.03*v;

			x = cos(uu) * sin(vv);
			y = sin(uu) * sin(vv);
			z = cos(vv);

			xx = ((2*pow(x,2) -pow(y,2)-pow(z,2)+2*y*z*(pow(y,2)-pow(z,2)))+z*x*(pow(x,2)-pow(z,2))+x*y*(pow(y,2)-pow(x,2)))*0.5;
			yy = (pow(y,2)-pow(z,2)+(z*x*(pow(z,2)-pow(x,2))+x*y*(pow(y,2)-pow(x,2))))*0.86;
			zz = ((x+y+z)*(pow((x+y+z),3)))+(4*(y-x)*(y-x)*(x-z));

			xx = xx*1;
			yy = yy*5;
			zz = zz/8;

			editPoints.append(MPoint(xx,yy,zz));
		}

		curveFn.createWithEditPoints(editPoints, 3, MFnNurbsCurve::kClosed, false, false, false, MObject::kNullObj,&stat);
	}

	return MS::kSuccess;
}